/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * NuevoSeguimiento.java
 *
 * Created on 21-ene-2013, 15:36:28
 */
package gui;

import com.sun.awt.AWTUtilities;
import controladores.ControladorPrincipal;
import io.Caso;
import io.Seguimiento;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Shape;
import java.awt.geom.RoundRectangle2D;
import java.awt.print.PageFormat;
import java.awt.print.Paper;
import java.awt.print.Printable;
import java.awt.print.PrinterJob;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Iterator;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import utilidades.JFrameConFondo;

/**
 *
 * @author NiCo
 */
public class EliminarSeguimiento extends JFrameConFondo implements Printable {

    private Image icono = new ImageIcon(getClass().getResource("/imagenes/logo.png")).getImage();
    private final Seguimiento seg;

    /** Creates new form NuevoSeguimiento */
    public EliminarSeguimiento(Seguimiento seg) {
        initComponents();
        this.seg = seg;
        cargarDatos();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        btnCerrar = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        jLabel30 = new javax.swing.JLabel();
        txtEquipoInterviniente = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        txtNroCaso = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        dtpFecha = new com.toedter.calendar.JDateChooser();
        jLabel31 = new javax.swing.JLabel();
        txtNombreNinio = new javax.swing.JTextField();
        jLabel32 = new javax.swing.JLabel();
        txtEdad = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        txtSituacion = new javax.swing.JTextArea();
        jScrollPane2 = new javax.swing.JScrollPane();
        txtIntervencion = new javax.swing.JTextArea();
        btnGuardar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        btnCerrar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/cerrar-normal.png"))); // NOI18N
        btnCerrar.setBorder(null);
        btnCerrar.setBorderPainted(false);
        btnCerrar.setFocusPainted(false);
        btnCerrar.setName("btnCerrar"); // NOI18N
        btnCerrar.setOpaque(false);
        btnCerrar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                btnCerrarMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                btnCerrarMouseExited(evt);
            }
            public void mousePressed(java.awt.event.MouseEvent evt) {
                btnCerrarMousePressed(evt);
            }
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                btnCerrarMouseReleased(evt);
            }
        });
        btnCerrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCerrarActionPerformed(evt);
            }
        });

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/titulo-eliminar-seguimiento.png"))); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Datos del caso", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 12))); // NOI18N
        jPanel3.setName("jPanel3"); // NOI18N

        jLabel30.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel30.setText("Equipo interviniente");
        jLabel30.setName("jLabel30"); // NOI18N

        txtEquipoInterviniente.setEditable(false);
        txtEquipoInterviniente.setFont(new java.awt.Font("Tahoma", 0, 12));
        txtEquipoInterviniente.setName("txtEquipoInterviniente"); // NOI18N

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel3.setText("Fecha");
        jLabel3.setName("jLabel3"); // NOI18N

        txtNroCaso.setEditable(false);
        txtNroCaso.setFont(new java.awt.Font("Tahoma", 0, 16));
        txtNroCaso.setName("txtNroCaso"); // NOI18N

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 16));
        jLabel2.setText("Nº de caso");
        jLabel2.setName("jLabel2"); // NOI18N

        dtpFecha.setDateFormatString("dd/MM/yyyy");
        dtpFecha.setEnabled(false);
        dtpFecha.setFont(new java.awt.Font("Tahoma", 0, 12));
        dtpFecha.setName("dtpFecha"); // NOI18N

        jLabel31.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel31.setText("Nombre del niño");
        jLabel31.setName("jLabel31"); // NOI18N

        txtNombreNinio.setEditable(false);
        txtNombreNinio.setFont(new java.awt.Font("Tahoma", 0, 12));
        txtNombreNinio.setName("txtNombreNinio"); // NOI18N

        jLabel32.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel32.setText("Edad");
        jLabel32.setName("jLabel32"); // NOI18N

        txtEdad.setEditable(false);
        txtEdad.setFont(new java.awt.Font("Tahoma", 0, 12));
        txtEdad.setName("txtEdad"); // NOI18N

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addGap(5, 5, 5)
                        .addComponent(txtNroCaso, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel30)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(txtEquipoInterviniente, javax.swing.GroupLayout.DEFAULT_SIZE, 215, Short.MAX_VALUE))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel31)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(txtNombreNinio, javax.swing.GroupLayout.PREFERRED_SIZE, 188, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel32)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(txtEdad, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(43, 43, 43)
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(dtpFecha, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(txtNroCaso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(20, 20, 20)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel31)
                    .addComponent(txtNombreNinio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel32)
                        .addComponent(txtEdad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(dtpFecha, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 11, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel30)
                    .addComponent(txtEquipoInterviniente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel4.setText("Situación - Problema");
        jLabel4.setName("jLabel4"); // NOI18N

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel5.setText("Intervención realizada");
        jLabel5.setName("jLabel5"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        txtSituacion.setColumns(20);
        txtSituacion.setEditable(false);
        txtSituacion.setFont(new java.awt.Font("Tahoma", 0, 12));
        txtSituacion.setLineWrap(true);
        txtSituacion.setRows(1);
        txtSituacion.setName("txtSituacion"); // NOI18N
        jScrollPane1.setViewportView(txtSituacion);

        jScrollPane2.setName("jScrollPane2"); // NOI18N

        txtIntervencion.setColumns(20);
        txtIntervencion.setEditable(false);
        txtIntervencion.setFont(new java.awt.Font("Tahoma", 0, 12));
        txtIntervencion.setLineWrap(true);
        txtIntervencion.setRows(5);
        txtIntervencion.setName("txtIntervencion"); // NOI18N
        jScrollPane2.setViewportView(txtIntervencion);

        btnGuardar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/eliminar.png"))); // NOI18N
        btnGuardar.setBorderPainted(false);
        btnGuardar.setFocusPainted(false);
        btnGuardar.setName("btnGuardar"); // NOI18N
        btnGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGuardarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(75, 75, 75)
                        .addComponent(btnCerrar))
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 381, Short.MAX_VALUE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 381, Short.MAX_VALUE)
                    .addComponent(jLabel4)
                    .addComponent(jLabel5)
                    .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnGuardar, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 142, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(btnCerrar)
                    .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 30, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 142, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(11, 11, 11)
                .addComponent(btnGuardar, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnCerrarMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnCerrarMouseEntered

        btnCerrar.setIcon(new ImageIcon(getClass().getResource("/imagenes/cerrar-activo.png")));     }//GEN-LAST:event_btnCerrarMouseEntered

    private void btnCerrarMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnCerrarMouseExited

        btnCerrar.setIcon(new ImageIcon(getClass().getResource("/imagenes/cerrar-normal.png")));     }//GEN-LAST:event_btnCerrarMouseExited

    private void btnCerrarMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnCerrarMousePressed

        btnCerrar.setIcon(new ImageIcon(getClass().getResource("/imagenes/cerrar-click.png")));     }//GEN-LAST:event_btnCerrarMousePressed

    private void btnCerrarMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnCerrarMouseReleased

        btnCerrar.setIcon(new ImageIcon(getClass().getResource("/imagenes/cerrar-normal.png")));     }//GEN-LAST:event_btnCerrarMouseReleased

    private void btnCerrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCerrarActionPerformed
        this.dispose();
    }//GEN-LAST:event_btnCerrarActionPerformed

    private void btnGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGuardarActionPerformed
        MensajesConf p2 = new MensajesConf("Eliminar", this);
        p2.setLocationRelativeTo(null);
        p2.setIconImage(icono);
        p2.setVisible(true);
        Shape shape = new RoundRectangle2D.Float(0, 0, p2.getWidth(), p2.getHeight(), 30, 30);
        AWTUtilities.setWindowShape(p2, shape);
    }//GEN-LAST:event_btnGuardarActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCerrar;
    private javax.swing.JButton btnGuardar;
    private com.toedter.calendar.JDateChooser dtpFecha;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel30;
    private javax.swing.JLabel jLabel31;
    private javax.swing.JLabel jLabel32;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTextField txtEdad;
    private javax.swing.JTextField txtEquipoInterviniente;
    private javax.swing.JTextArea txtIntervencion;
    private javax.swing.JTextField txtNombreNinio;
    private javax.swing.JTextField txtNroCaso;
    private javax.swing.JTextArea txtSituacion;
    // End of variables declaration//GEN-END:variables

    @Override
    public int print(Graphics g, PageFormat f, int pageIndex) {
        SimpleDateFormat sdf = new java.text.SimpleDateFormat("dd/MM/yyyy");
        if (pageIndex == 0) {
            try {
                // Imprime "Hola mundo" en la primera pagina, en la posicion 100,100
                Image img = ImageIO.read(new File("src/imagenes/ficha-seguimiento.png").toURI().toURL());
                g.drawImage(img, 52, 0, 491, 801, null);
            } catch (Exception ex) {
            }
            //datos del caso
            g.setFont(new Font("Tahoma", Font.BOLD, 18));
            g.drawString(txtNroCaso.getText(), 141, 166);
            g.setFont(new Font("Tahoma", Font.PLAIN, 11));
            g.drawString(sdf.format(dtpFecha.getDate()), 111, 198);
            g.drawString(txtEquipoInterviniente.getText(), 219, 222);
            g.drawString(txtNombreNinio.getText(), 181, 282);
            g.drawString(txtEdad.getText(), 477, 282);

            int cont = 0;
            int renglon = 0;
            String aux[] = txtSituacion.getText().split(" ");
            ArrayList<String> lineas = new ArrayList<String>();
            while (aux.length > cont + 1) {
                String cadena = "";
                cadena = aux[cont];
                while (cont < aux.length - 1 && cadena.length() <= 85) {
                    cont++;
                    cadena = cadena + " " + aux[cont];
                }
                cont++;
                lineas.add(cadena);
            }
            Iterator<String> it = lineas.iterator();
            while (it.hasNext()) {
                g.drawString(it.next(), 60, (323 + (renglon * 18)));
                renglon++;
            }

            cont = 0;
            renglon = 0;
            aux = txtIntervencion.getText().split(" ");
            lineas = new ArrayList<String>();
            while (aux.length > cont + 1) {
                String cadena = "";
                cadena = aux[cont];
                while (cont < aux.length - 1 && cadena.length() <= 85) {
                    cont++;
                    cadena = cadena + " " + aux[cont];
                }
                cont++;
                lineas.add(cadena);
            }
            it = lineas.iterator();
            while (it.hasNext()) {
                g.drawString(it.next(), 60, (444 + (renglon * 18)));
                renglon++;
            }
            return PAGE_EXISTS;
        } else {
            return NO_SUCH_PAGE;
        }
    }

    private void cargarDatos() {
        txtNroCaso.setText(String.valueOf(seg.getCaso().getNumeroCaso()));
        txtEdad.setText(String.valueOf(seg.getCaso().getNino_adolescente().getEdad()));
        txtNombreNinio.setText(String.valueOf(seg.getCaso().getNino_adolescente().toString()));
        txtEquipoInterviniente.setText(seg.getEquipoInterviniente());
        dtpFecha.setDate(seg.getFecha());
        txtSituacion.setText(seg.getSituacioProblema());
        txtIntervencion.setText(seg.getIntervencionRealizada());
    }

    public void confirmado() {
        ControladorPrincipal.getInstance().eliminar(this.seg);
        MensajesInfo p1 = new MensajesInfo('n', "EliminarExito");
        p1.setLocationRelativeTo(null);
        p1.setIconImage(icono);
        p1.setVisible(true);
        Shape shape = new RoundRectangle2D.Float(0, 0, p1.getWidth(), p1.getHeight(), 30, 30);
        AWTUtilities.setWindowShape(p1, shape);
        this.dispose();
    }
}
